package com.khotyn.heresy.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.khotyn.heresy.bean.PictureBrief;
import com.khotyn.heresy.bean.PictureDetail;
import com.khotyn.heresy.dao.PictureDAO;

/**
 * 图片DAO iBATIS实现
 * 修改:增加了对图片可删除标记位的更改
 * @author 黄挺
 */
public class PictureDAOIbatisImpl extends SqlMapClientDaoSupport implements PictureDAO {

	public String insertPicture(PictureDetail picDetail) {
		return (String) this.getSqlMapClientTemplate().insert("insertPicture", picDetail);
	}

	public int updatePictureDelFlag(PictureDetail picDetail) {
		return this.getSqlMapClientTemplate().update("updatePictureDelFlag", picDetail);
	}

	public int updatePictureByID(PictureDetail picDetail) {
		return this.getSqlMapClientTemplate().update("updatePictureByID", picDetail);
	}

	public PictureBrief selectPicBriefByPicId(String pictureID) {
		return (PictureBrief) this.getSqlMapClientTemplate().queryForObject("selectPicBriefByPicId", pictureID);
	}

	@SuppressWarnings("unchecked")
	public List<PictureBrief> selectPagedPicBriefByAlbumId(Integer albumID,
			Integer minRow, Integer maxRow, String flagSortType) {
		Map map = new HashMap();
		map.put("albumID", albumID);
		map.put("minRow", minRow);
		map.put("maxRow", maxRow);
		map.put("flagSortType", flagSortType);
		return this.getSqlMapClientTemplate().queryForList("selectPagedPicBriefByAlbumId", map);
	}

	@SuppressWarnings("unchecked")
	public List<PictureBrief> selectPicBriefByPicName(String pictureName,
			Integer minRow, Integer maxRow) {
		Map map = new HashMap();
		map.put("pictureName", pictureName);
		map.put("minRow", minRow);
		map.put("maxRow", maxRow);
		
		return this.getSqlMapClientTemplate().queryForList("selectPicBriefByPicName", map);
	}

	public PictureDetail selectPicByPicID(String pictureID) {
		return (PictureDetail) this.getSqlMapClientTemplate().queryForObject("selectPicByPicID", pictureID);
	}

	@SuppressWarnings("unchecked")
	public int updatePicScore(String pictureID, Integer score) {
		Map map = new HashMap();
		map.put("pictureID", pictureID);
		map.put("score", score);
		return this.getSqlMapClientTemplate().update("updatePicScore", map);
	}

	public String selectLocationByPicID(String pictureID) {
		return (String) this.getSqlMapClientTemplate().queryForObject("selectLocationByPicID", pictureID);
	}

	@SuppressWarnings("unchecked")
	public int updatePictureCheckFlag(String pictureID, String flagCheck) {
		Map map = new HashMap();
		map.put("pictureID", pictureID);
		map.put("flagCheck", flagCheck);
		
		return this.getSqlMapClientTemplate().update("updatePictureCheckFlag", map);
	}

	@SuppressWarnings("unchecked")
	public List<PictureBrief> selectReportedPicture(Integer minRow, Integer maxRow) {
		Map map = new HashMap();
		map.put("minRow", minRow);
		map.put("maxRow", maxRow);
		return this.getSqlMapClientTemplate().queryForList("selectReportedPicture", map);
	}

	public Integer selectTotalScore(String pictureID) {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("selectTotalScore", pictureID);
	}

	@SuppressWarnings("unchecked")
	public List<PictureBrief> selectRecentUploadPicture(Integer userID,
			Integer maxRow) {
		Map map = new HashMap();
		map.put("userID", userID);
		map.put("maxRow", maxRow);
		return this.getSqlMapClientTemplate().queryForList("selectRecentUploadPicture", map);
	}

	@SuppressWarnings("unchecked")
	public int updateCollectCount(String pictureID, Integer collectCount) {
		Map map = new HashMap();
		map.put("pictureID", pictureID);
		map.put("collectCount", collectCount);
		return this.getSqlMapClientTemplate().update("updateCollectCount", map);
	}

	public Integer selectReportedPictureCount() {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("selectReportedPictureCount");
	}

	@SuppressWarnings("unchecked")
	public List<PictureBrief> selectRecentUploadPublicPic(Integer maxRow) {
		return this.getSqlMapClientTemplate().queryForList("selectRecentUploadPublicPic", maxRow);
	}

	public Integer selectPicCountByPicName(String name) {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("selectPicCountByPicName", name);
	}

	@SuppressWarnings("unchecked")
	public int updatePicLocation(String pictureID, String location) {
		Map map = new HashMap();
		map.put("pictureID", pictureID);
		map.put("location", location);
		
		return this.getSqlMapClientTemplate().update("updatePicLocation", map);
	}

	public Integer selectPicOwnerId(String pictureID) {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("selectPicOwnerId", pictureID);
	}

	public String selectThumbLocation(String pictureID) {
		return (String) this.getSqlMapClientTemplate().queryForObject("selectThumbLocation", pictureID);
	}
}
